<template>
  <div class="my-address">
    <!-- 头部 -->
    <NavigationBar title="收货地址"></NavigationBar>
    <div class="address-list" v-if="myAddress.length>0">
      <div class="address" v-for="(item,index) in myAddress" :key="index">
        <img class="left" v-if="item.is_default" src="https://files.roborock.com/images_h5/image/default_address.png"
             alt="">
        <div class="center">
          <p class="mydata">
            <span class="name">{{ item.name }}</span>
            <span class="phone">{{ item.mobile }}</span>
            <span class="default" v-if="item.is_default">默认</span>
          </p>
          <p class="myadd">{{
              item.regions.reduce((prev, item) => {
                return prev + item.name
              }, '')
            }}</p>
        </div>
        <div class="right" @click="$router.push({name:'address',params:{type:'up',id:item.id}})">
          <img src="https://files.roborock.com/images_h5/image/edit_address.png" alt="">
        </div>
      </div>
    </div>
    <van-empty
      v-else
      class="custom-image"
      image="https://files.roborock.com/mini_img/address/emptyAddress.png"
      description="收货地址为空"
    />
    <div class="add-address">
      <van-button round size="large" type="info" :to="{name:'address',params:{type:'add'}}">添加地址</van-button>
    </div>
  </div>
</template>

<script>
export default {
  name: "MyAddress",
  data() {
    return {
      myAddress: []
    }
  },
// 侦听器
  watch: {},
// 计算属性
  computed: {},
// 事件
  methods: {
    toEdit() {

    }
  },
// 生命周期
  created() {
  },
  mounted() {
    this.$ajax.myAddress().then(res => {
      // console.log(res)
      if (res.error_code === 0) {
        this.myAddress = res.consignees;
      } else {
        this.$toast(res.error_desc)
      }
      // console.log(this.myAddress);
    })
  }
}
</script>

<style lang="scss" scoped>
.my-address {
  ::v-deep.custom-image {
    margin-top: 200px;

    .van-empty__image {
      width: 93px;
      height: 93px;
    }
  }

  .address-list {
    width: 100%;
    margin-top: 15px;
    box-sizing: border-box;
    padding: 0 18px 75px;

    .address {
      box-sizing: border-box;
      border-bottom: 0.5px solid #e4e4e4;
      padding: 18px 20px;
      display: flex;
      align-items: center;

      > img {
        height: 40px;
        width: 40px;
        margin-right: 20px;
      }

      .center {
        display: inline-block;
        box-sizing: border-box;
        flex: 1;
        color: #4a4a4a;
        font-weight: 400;
        font-size: 14px;
        line-height: 20px;

        p.mydata {
          .name {
            color: #4a4a4a;
            font-weight: 400;
            font-size: 14px;
            line-height: 20px;
          }

          .phone {
            margin-left: 12px;
            color: #4a4a4a;
            font-weight: 400;
            font-size: 14px;
            line-height: 20px;
          }

          .default {
            text-align: center;
            box-sizing: border-box;
            border: 1px solid #e22920;
            border-radius: 5px;
            font-size: 12px;
            height: 18px;
            line-height: 18px;
            margin-left: 10px;
            color: #e22920;
            padding: 0 5px;
          }
        }

        p.myadd {
          font-size: 14px;
          margin-top: 5px;
          color: #4a4a4a;
          font-weight: 400;
          line-height: 20px;
        }

        p:last-child {
          font-size: 14px;
          margin-top: 5px;
          overflow: hidden;
          color: #4a4a4a;
          font-weight: 400;
          line-height: 20px;

        }
      }

      .right {
        img {
          width: 24px;
          height: 24px;
        }
      }
    }
  }

  .add-address {
    position: fixed;
    padding: 20px 42px 30px;
    left: 0;
    right: 0;
    bottom: 0;
    background: #f5f5f5;

    .van-button--info {
      background: linear-gradient(270deg, #3777f7, #72b4fe);
      height: 40px;
    }
  }

}

</style>